package smartfleet.mobile.rest.webservice.sync.database;

import java.util.ArrayList;
import java.util.Collection;

import smartfleet.mobile.location.Location;
import smartfleet.mobile.rest.webservice.location.LocationWebServiceUtil;
import smartfleet.mobile.rest.webservice.traveller.TravellerWebServiceUtil;
import smartfleet.mobile.rest.webservice.vehicle.VehicleWebServiceUtil;
import smartfleet.mobile.traveller.Traveller;
import smartfleet.mobile.trip.Trip;
import smartfleet.mobile.vehicle.Vehicle;

public class DatabaseSyncWebServiceUtil {

	 
	public static String syncDatabases(ArrayList<Trip>  listOfTrips){
		String result="db replicated on server";
		
		for(Trip trip: listOfTrips){
			
			Collection<Location> locations = trip.getLocations();
			Vehicle vehicle = trip.getVehicle();
			Collection<Traveller> travellers = trip.getTravellers();
			
			VehicleWebServiceUtil.registerOrUpdateVehicleInfo(vehicle);
			
			for(Location loc:locations)
				LocationWebServiceUtil.registerLocationInfo(loc);
			
			for(Traveller traveller: travellers)
				TravellerWebServiceUtil.save(traveller);
			
		}
		
		return result;
	}
}
